package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PostManager;
import com.ruoyi.system.service.IPostManagerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 主贴Controller
 * 
 * @author ruoyi
 * @date 2022-10-08
 */
@RestController
@RequestMapping("/system/postManager")
public class PostManagerController extends BaseController
{
    @Autowired
    private IPostManagerService postManagerService;

    /**
     * 查询主贴列表
     */
    @PreAuthorize("@ss.hasPermi('system:postManager:list')")
    @GetMapping("/list")
    public TableDataInfo list(PostManager postManager)
    {
        startPage();
        List<PostManager> list = postManagerService.selectPostManagerList(postManager);
        return getDataTable(list);
    }

    /**
     * 导出主贴列表
     */
    @PreAuthorize("@ss.hasPermi('system:postManager:export')")
    @Log(title = "主贴", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostManager postManager)
    {
        List<PostManager> list = postManagerService.selectPostManagerList(postManager);
        ExcelUtil<PostManager> util = new ExcelUtil<PostManager>(PostManager.class);
        util.exportExcel(response, list, "主贴数据");
    }

    /**
     * 获取主贴详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:postManager:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(postManagerService.selectPostManagerById(id));
    }

    /**
     * 新增主贴
     */
    @PreAuthorize("@ss.hasPermi('system:postManager:add')")
    @Log(title = "主贴", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostManager postManager)
    {
        postManager.setCreateBy(getUsername());
        return toAjax(postManagerService.insertPostManager(postManager));
    }

    /**
     * 修改主贴
     */
    @PreAuthorize("@ss.hasPermi('system:postManager:edit')")
    @Log(title = "主贴", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostManager postManager)
    {
        return toAjax(postManagerService.updatePostManager(postManager));
    }

    /**
     * 删除主贴
     */
    @PreAuthorize("@ss.hasPermi('system:postManager:remove')")
    @Log(title = "主贴", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(postManagerService.deletePostManagerByIds(ids));
    }
}
